package com.gd.iot.energy.controller.statistics;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.consts.SystemConsts;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.common.vo.ChartVO;
import com.gd.iot.energy.pojo.statistics.vo.StatisticsPageVO;
import com.gd.iot.energy.service.statistics.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 统计分析-用量分析-同比分析
 *
 * @author kris
 * @date Created at 2020/8/11 10:50
 */
@Api(value = "统计分析-用量分析-同比分析",tags = "统计分析-用量分析-同比分析")
@RestController
@RequestMapping("/admin/yearOnYear")
public class YearOnYearController {

    @Autowired
    private StatisticsService statisticsService;

    @ApiOperation("同比用量分页列表")
    @SystemLogRecordMonitor("同比用量分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerType", value = "(0, 居民 使用)" +
                    "(1, 商业 使用)" +
                    "( 2, 工业 使用)" +
                    "( 3, 农业 使用)" +
                    "(4,教育 使用)" +
                    "( 5, 医疗 使用)" +
                    "( 6,政府及事业单位 使用)" +
                    "( 7, 其他 使用)", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "cycle", value = "统计周期，(日, 0)(月, 1)(季, 2)(年, 3)", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "date", value = "日期，如果季度，传 0,1,2,3", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getStatisticsPageVO")
    public ResponseEntity<PageVO<StatisticsPageVO>> getStatisticsPageVO(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "customerName",required = false)String customerName,
            @RequestParam(value = "customerType",required = false)String customerType,
            @RequestParam(value = "cycle",required = true)String cycle,
            @RequestParam(value = "date",required = true)String date,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "a.archives") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<StatisticsPageVO> pageVO = statisticsService.getYearOnYearStatisticsPageVO(customerSerialnumber,customerName,
                customerType,cycle,date,areaId,pageSize,pageNum,orderColumn,orderType, SystemConsts.StatisticsType.YEAR_TO_YEAR);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("同比用量图表")
    @SystemLogRecordMonitor("同比用量图表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerType", value = "(0, 居民 使用)" +
                    "(1, 商业 使用)" +
                    "( 2, 工业 使用)" +
                    "( 3, 农业 使用)" +
                    "(4,教育 使用)" +
                    "( 5, 医疗 使用)" +
                    "( 6,政府及事业单位 使用)" +
                    "( 7, 其他 使用)", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "cycle", value = "统计周期，(日, 0)(月, 1)(季, 2)(年, 3)", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "date", value = "日期，如果季度，传 0,1,2,3", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getStatisticsChartVO")
    public ResponseEntity<List<ChartVO>> getStatisticsChartVO(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "customerName",required = false)String customerName,
            @RequestParam(value = "customerType",required = false)String customerType,
            @RequestParam(value = "cycle",required = true)String cycle,
            @RequestParam(value = "date",required = true)String date,
            @RequestParam(value = "areaId",required = false)Integer areaId
    ) {

        List<ChartVO> chartVOS = statisticsService.getStatisticsChartVO(customerSerialnumber,customerName,
                customerType,cycle,date,areaId,SystemConsts.StatisticsType.YEAR_TO_YEAR);
        return new ResponseEntity<>(chartVOS);
    }
}
